﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CourseUtils;

namespace luckyTicket
{
    class LuckyTicket
    {
        static void checkTicket(int[] number)
        {

            if (number[0] + number[1] + number[2] == number[3] + number[4] + number[5])
            {
                Console.WriteLine("Билет счастливый");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Билет не счастливый");
                Console.ReadKey();
            }
        }

        static int[] convertToArray (int ticketNumber)
        {
            int a = ticketNumber;
            int i = 0;
            int[] digitArray = new int[6];
            for (i = 0; a > 0; i++)
            {
                digitArray[i] = a % 10;
                a /= 10;
            }
                return digitArray;
        }

        static bool checkNumberLenght(int ticketNumber)
        {
            bool result = true;
            int counter = 0;
            while (ticketNumber > 0)
            {
                counter++;
                ticketNumber /= 10;
            }

            if (counter == 6)
            {
                return result;
            }
            return !result;
          
        }

        static void Main(string[] args)
        {
            int ticketNumber;
            do
            {
                ticketNumber = IOHelpers.ReadIntFromConsole("Введите номер билета");
                
                if (LuckyTicket.checkNumberLenght(ticketNumber))
                {
                    LuckyTicket.checkTicket(LuckyTicket.convertToArray(ticketNumber));
                }
                else
                {
                    Console.WriteLine("Ошибка: введите шестизначный номер билета");
                }
               
            } while (!LuckyTicket.checkNumberLenght(ticketNumber));
        }
    }
}
